//index.js
//获取应用实例
var app = getApp()
Page({
    data: {
        ordersLength:0,

        importordersLength:0,
        allordersLength:0,
        tabArr: {
            curHdIndex: 0,
            curBdIndex: 0
        },
        currentTab: 0,
        tabArray: ["已审订单", "未审订单", "订单汇总"],
       
    },

    onLoad: function (options) {
        this.getMyOrder("orders");
        this.getMyOrder("importorders");
    },
    getMyOrder:function(e){
        var $that = this;
       
        app.util.request({
            url: 'entry/wxapp/Orders',
            data: {
                "m": 'nets_haojk',
                "uri": e+""
            },
            method: 'post',
            success: function (response) {
             
                var obj = response.data.data;
                for (var i = 0; i < obj.length; i++) {
                  obj[i].orderTime = form_time(obj[i].orderTime);
                }
                if(e=="orders"){
                 
                    $that.setData({
                        ordersLength: obj.length,
                    });
                    $that.setData({
                      orderInforArray: obj,
                    });
                } else if (e == "importorders"){
                    $that.setData({
                        importordersLength: obj.length,
                    });
                   
                    $that.setData({
                      importordersArray: obj,
                    });
                }

                //int转时间戳
                function form_time(a) {
                    var myDate = new Date(parseInt(a) * 1000);
                    var datestr = "";
                    datestr = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
                    datestr = datestr + "-" + (myDate.getMonth() + 1);       //获取当前月份(0-11,0代表1月)
                    datestr = datestr + "-" + myDate.getDate();        //获取当前日(1-31)
                    return datestr;
                }
            }
        })
    },
    //事件处理函数
    tabFun: function (e) {
        var $that = this;
        //获取触发事件组件的dataset属性  
        var _datasetId = e.target.dataset.id;
        var _obj = {};
        _obj.curHdIndex = _datasetId;
        _obj.curBdIndex = _datasetId;
        this.setData({
            tabArr: _obj
        });
      
        if (_obj.curHdIndex==0){
            //$that.getMyOrder("orders");
        } else if (_obj.curHdIndex == 1){
           
            //$that.getMyOrder("importorders");
        } else if (_obj.curHdIndex == 2){
            //$that.getMyOrder("orders");
        }
    },
    //事件处理函数
    bindViewTap: function () {
        wx.navigateTo({
            url: '../detail/index'
        })
    },
})
